package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.entity.vo.merchantPledgeTask.MerchantPledgeCollectionRewardsVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MerchantPledgeTaskSettlementRewardsLog;
import com.sc.nft.mapper.MerchantPledgeTaskSettlementRewardsLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 商户质押任务奖励结算日志表(sc_merchant_pledge_task_settlement_rewards_log)数据DAO
 *
 * @author Sun
 * @since 2023-08-24 16:16:49
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class MerchantPledgeTaskSettlementRewardsLogDao extends ServiceImpl<MerchantPledgeTaskSettlementRewardsLogMapper, MerchantPledgeTaskSettlementRewardsLog> {

    public MerchantPledgeTaskSettlementRewardsLog getNextRewardsTimeByUserRecordsId(Long id) {
        LambdaQueryWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getUserPledgeTaskRecordsId,id);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getIsSettlement,Boolean.FALSE);
        wrapper.last("order by id  limit 1");
        return getOne(wrapper);
    }

    public List<MerchantPledgeTaskSettlementRewardsLog> getPledgeTaskSettlementRewards() {
        return baseMapper.getPledgeTaskSettlementRewards();
    }

    public boolean updateIsSettlementById(Boolean isSettlement,Long id) {
        LambdaUpdateWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getId,id);
        wrapper.set(MerchantPledgeTaskSettlementRewardsLog::getIsSettlement,isSettlement);
        return update(wrapper);
    }

    public Integer getCountByIsSettlementAndId(Boolean isSettlement, Long id) {
        LambdaQueryWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.ne(MerchantPledgeTaskSettlementRewardsLog::getUserPledgeTaskRecordsId,id);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getIsSettlement,isSettlement);
        return count(wrapper);
    }

    public boolean delByUserIdAndUserPledgeTaskRecordsId(Long userId, Long userPledgeTaskRecordsId) {
        LambdaQueryWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getUserId,userId);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getUserPledgeTaskRecordsId,userPledgeTaskRecordsId);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getIsSettlement,Boolean.FALSE);
        return remove(wrapper);
    }
    public boolean delByUserPledgeTaskRecordsId(Long userPledgeTaskRecordsId) {
        LambdaQueryWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getUserPledgeTaskRecordsId,userPledgeTaskRecordsId);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getIsSettlement,Boolean.FALSE);
        return remove(wrapper);
    }

    public boolean delIncomeRecordsByUserIdAndUserPledgeTaskRecordsId(Long userId, Long userPledgeTaskRecordsId) {
        LambdaQueryWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getFromUserId,userId);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getFromUserRecordsId,userPledgeTaskRecordsId);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getIsSettlement,Boolean.FALSE);
        return remove(wrapper);
    }
    public boolean delIncomeRecordsByUserPledgeTaskRecordsId( Long userPledgeTaskRecordsId) {
        LambdaQueryWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getFromUserRecordsId,userPledgeTaskRecordsId);
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getIsSettlement,Boolean.FALSE);
        return remove(wrapper);
    }

    public boolean deleteById(Long id) {
        LambdaUpdateWrapper<MerchantPledgeTaskSettlementRewardsLog> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MerchantPledgeTaskSettlementRewardsLog::getId,id);
        return remove(wrapper);
    }
}